"""
解析大乐透中奖记录 并落库
"""
import math

import requests
import json
import pymysql
url = 'https://webapi.sporttery.cn/gateway/lottery/getHistoryPageListV1.qry?gameNo=85&provinceId=0&pageSize=30&isVerify=1&pageNo=1'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36'
}
response = requests.get(url=url,headers=headers)
data = response.json()
total = data['value']['total']
pagesize = 100
page = math.ceil(total / pagesize)
for i in range(page,-1,-1):
    if i != 0:
        url2 = 'https://webapi.sporttery.cn/gateway/lottery/getHistoryPageListV1.qry?gameNo=85&provinceId=0&pageSize=' + str(
            pagesize) + '&isVerify=1&pageNo=' + str(i)
        print(url2)
        response1 = requests.get(url=url2, headers=headers)
        data1 = response1.json()
        arrays = data1['value']['list']
        for a in arrays:
            result = a['lotteryDrawResult']
            time = a['lotteryDrawTime']
            num = a['lotteryDrawNum']
            print(f'当前期数：{num}，开奖时间：{time}，中奖号码：{result}')
            """操作数据库"""
            # conn = pymysql.connect(host='10.4.5.5', port=3306, user='root', passwd='root', db='phoeix')
            # cur = conn.cursor()
            # sql = "INSERT INTO lottery (num,time,result) VALUES (%s,%s,%s) "
            # params = (num, time, result)
            # cur.execute(sql, params)
            # conn.commit()
            # cur.close()
            # conn.close()

            """写入文本"""











